package main.chapter2

private const val DEBUG = 1
private const val USER = 0
fun main(args: Array<String>) {

    //分支表达式，if的最后一句是返回值
    val mode = if (args.isNotEmpty() && args[0] == "1") {
        DEBUG
    } else {
        USER
    }

    println(mode)

    //分支语句
    val x=5
    when(x){
        is Int-> println("Hello,$x")
        in 0..100-> println("x is in 0..100")
        !in 1..100-> println("x is not in 1..100")
        args[0].toInt()-> println("x==arg[0]")
    }

    val mode1=when{
        args.isNotEmpty()&&args[0]=="1"-> DEBUG
        else-> USER

    }
    //中缀表达式
    if (Book() on Desk()) {

    }
}

class Book {
    //中缀表达式
    infix fun on(any: Any): Boolean {
        return false
    }
}

class Desk


class Player{
    enum class State{
        IDLE,BUFFERING,PLAYING,PAUSE
    }

    private var state=State.IDLE
    fun pause(){
        when(state){
            State.BUFFERING,State.PLAYING->doPause()
            else->{
                println("其他情况的操作")
            }
        }
    }

    private fun doPause() {
        println("暂停")
    }
}